package com.zw.mes.module.cost.service;


import com.zw.mes.module.cost.mapper.DictCommonMapperNew;
import com.zw.mes.module.cost.model.DictCommon;
import com.zw.mes.module.cost.model.Equ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zw.mes.module.cost.model.Process;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class DictCommonService {
    @Autowired
    private DictCommonMapperNew dictCommonMapper;

    /** 按分类查询字典数据 */
    public List<DictCommon> findDictByGroupName(String groupName) {
        List<DictCommon> dictCommonList = dictCommonMapper.findByGroupName(groupName);
        return dictCommonList;
    }


    public List<DictCommon> findDictByGroupNameAndSummary(String groupName, Integer cardStatus, Integer makeStatus, Integer outStatus,Integer paintStatus,String proCode,String special,String part) {
        List<DictCommon> dictCommonList = new ArrayList<>();

        if(outStatus==1){
            /** 外购件接收时常量为1*/
            List<DictCommon> dictCommons = dictCommonMapper.findByGroupNameAndSummary(groupName,1);
            dictCommons.get(0).setCountNumber(dictCommonMapper.countReportSee(proCode,special,part));
            dictCommonList.addAll(dictCommons);
        }

        if(makeStatus==1){
            /** 制作件接收时常量为2*/
            List<DictCommon> dictCommons = dictCommonMapper.findByGroupNameAndSummary(groupName,2);
            for (int i = 0; i < dictCommons.size(); i++) {
                if(dictCommons.get(i).getName().equals("制作件清单")){
                dictCommons.get(i).setCountNumber(dictCommonMapper.countMakeSee(proCode,special,part));
                }else if(dictCommons.get(i).getName().equals("图纸变更单")){
                dictCommons.get(i).setCountNumber(dictCommonMapper.countDrawSee(proCode,special,part));
                }
            }
            dictCommonList.addAll(dictCommons);
        }

        if(null!=paintStatus&& paintStatus==1){
            /** 涂装设计清单接收时常量为3*/
            List<DictCommon> dictCommons = dictCommonMapper.findByGroupNameAndSummary(groupName,3);
            dictCommons.get(0).setCountNumber(dictCommonMapper.countPaintSee(proCode,special,part));
            dictCommonList.addAll(dictCommons);
        }

        /** 工艺卡接收时常量为4*/
        if(cardStatus==1){
            List<DictCommon> dictCommons = dictCommonMapper.findByGroupNameAndSummary(groupName,4);
            for(int i = 0;i < dictCommons.size(); i++){
                if(dictCommons.get(i).getName().equals("工艺卡列表")){
                    dictCommons.get(i).setCountNumber(dictCommonMapper.conutCardSee(proCode,special,part));
                }else if(dictCommons.get(i).getName().equals("工艺路线")){
                    dictCommons.get(i).setCountNumber(dictCommonMapper.countRouteSee(proCode,special,part));
                }else if(dictCommons.get(i).getName().equals("机加工时")){
                    dictCommons.get(i).setCountNumber(dictCommonMapper.countMachHoursSee(proCode,special,part));
                }else if(dictCommons.get(i).getName().equals("机加工时汇总")){
                    dictCommons.get(i).setCountNumber(dictCommonMapper.countSummaryHoursSee(proCode));
                }
            }
            dictCommonList.addAll(dictCommons);
        }

        return dictCommonList;
    }



    /** 查询工序 */
    public List<Process> findProcesses() {
        return dictCommonMapper.findProcesses();
    }

    /** 查询设备 */
    public List<Equ> findEqu() {
        return dictCommonMapper.findEqu();
    }


}
